package com.lizardmind.haofudoctor.ui.main

import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.view.View
import com.linxiao.framework.activity.BaseActivity
import com.linxiao.framework.util.color
import com.linxiao.framework.util.getBaseFragmentStatePagerAdapter
import com.linxiao.framework.util.getDataBinding
import com.lizardmind.haofudoctor.R
import com.lizardmind.haofudoctor.databinding.ActivityMainBinding
import com.lizardmind.haofudoctor.ui.aboutMe.AboutMeFragment
import com.lizardmind.haofudoctor.ui.diagnosis.DiagnosisFragment
import com.lizardmind.haofudoctor.ui.studio.StudioFragment

class MainActivity : BaseActivity() {

    val binding by lazy { getDataBinding<ActivityMainBinding>(R.layout.activity_main) }

    private val list = arrayListOf(DiagnosisFragment(),StudioFragment(),AboutMeFragment())

    override fun onCreatRootView(): View  = binding.root

    override fun onInitView(savedInstanceState: Bundle?) {
        binding.apply {
            mainViewPager.setScanScroll(false)
            mainViewPager.adapter = getBaseFragmentStatePagerAdapter(supportFragmentManager,list)
            mainNavigation.binding(mainViewPager)
                    .setSelectTextViewChildImageFromResource(intArrayOf(R.mipmap.main_diagnosis_select,R.mipmap.main_studio_select,R.mipmap.main_aboutme_select))
                    .setUnselectTextViewChildImageFromResource(intArrayOf(R.mipmap.main_diagnosis_unselect,R.mipmap.main_studio_unselect,R.mipmap.main_aboutme_unselect))
                    .setTextViewChildTextFromString(resources.getStringArray(R.array.main_title))
                    .setUnSelectTextColor(color(R.color.button_gray))
                    .setSelectTextColor(Color.BLACK)
                    .setTextSize(10f)//文字大小，单位为sp，默认为42px
                    .commit()//提交，执行修改
        }
    }

    /**
     * 拦截返回键,使其退到桌面而不关闭app
     */
    override fun onBackPressed() {
        startActivity(object : Intent(Intent.ACTION_MAIN) {
            init {
                addCategory(Intent.CATEGORY_HOME)
            }
        })
    }

}